package com.ruoyi.project.lely.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.R;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.lely.constant.CommonConstant;
import com.ruoyi.project.lely.bean.entity.LyCategory;
import com.ruoyi.project.lely.mapper.LyCategoryMapper;
import com.ruoyi.project.lely.service.LyCategoryService;
import com.ruoyi.project.lely.bean.vo.LyCategoryCurrentVO;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * @Desc: 菜单实现
 * @Author LuoYong
 * @Date 2022/1/17 18:14
 */
@DataSource(value = DataSourceType.SLAVE)
@Service
public class LyCategoryServiceImpl extends ServiceImpl<LyCategoryMapper, LyCategory> implements LyCategoryService {

    /**
     * 当前分类菜单及子菜单
     */
    @Override
    public R getCurrent(Long id) {
        // 当前分类
        LyCategory currentCategory = this.getById(id);
        List<LyCategory> currentSubCategory = this.list(
                new LambdaQueryWrapper<LyCategory>()
                        .eq(LyCategory::getPid, id)
                        .eq(LyCategory::getDeleted, CommonConstant.DELETED)
        );
        LyCategoryCurrentVO vo = LyCategoryCurrentVO.builder()
                .currentCategory(currentCategory)
                .currentSubCategory(currentSubCategory).build();
        return R.ok(vo);
    }
}
